<template>
  <div id="boxx">
    <MyHeader title="商品列表页"></MyHeader>
    <MyTable :list="list">
      <template #header>
        <th>#</th>
        <th>商品名称</th>
        <th>价格</th>
        <th>标签</th>
        <th>操作</th>
      </template>

      <template #box="scope">
        <td>{{ scope.row.id }}</td>
        <td>{{ scope.row.goods_name }}</td>
        <td>{{ scope.row.goods_price }}</td>
        <td>{{ scope.row.tags }}</td>
        <td>
          <span
            v-for="(itme, index) in scope.row.tags"
            :key="index"
            class="badge bg-warning text-dark"
          >
            {{ itme }}
          </span>
        </td>
        <td>
          <button @click="btn(scope.row.id)" class="btn btn-danger btn-sm">
            删除
          </button>
        </td>
      </template>
    </MyTable>
  </div>
</template>

<script>
import MyTable from "../components/MyTable";
import MyHeader from "../components/MyHeader";

export default {
  components: {
    MyTable,
    MyHeader,
  },
  data() {
    return {
      list: [],
    };
  },
  async created() {
    let res = await this.$http({
      url: "/api/goods",
    });
    console.log(res);
    this.list = res.data.data;
  },
  methods: {
    btn(id) {
      let index = this.list.findIndex((item) => item.id === id);
      this.list.splice(index, 1);
    },
  },
};
</script>

<style lang="less" scoped>
#boxx {
  padding-top: 45px;
}
</style>